package com.pro.controller;

import com.pro.pojo.JsonData;
import com.pro.pojo.JsCarousel;
import com.pro.service.JsCarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * ClassName:JsCarouselController
 * Package:com.pro.controller
 * Description:  轮播图列表
 *
 * @Date:2021/11/12 下午 8:02
 * @Author: WYH
 */
@Controller
@RequestMapping("/banner")
public class JsCarouselController {

    @Autowired
    private JsCarouselService jsCarouselService;

    /**
     * @author WYH
     * @date 2021/11/14 下午 7:40
     * @content : 查询轮播图数据
     */
    @RequestMapping("/getAllBanner")
    @ResponseBody
    public JsonData getAllBanner(String display,String imgType,Integer limit, Integer page) {
        display = display  != null  ? "%"+display+"%":"%%";
        imgType = imgType = imgType != null ? "%"+imgType+"%":"%%";
        List<JsCarousel> allBanner = jsCarouselService.getAllBanner(display,imgType,limit, page);
        int count = jsCarouselService.count(display, imgType);
        return allBanner != null ? JsonData.buildSuccess(allBanner,count):JsonData.buildError("数据格式异常");
    }

    /**
     * @author WYH
     * @date 2021/11/14 下午 7:58
     * @content : 查看单个轮播对象
     */
    @RequestMapping("/getBanner")
    @ResponseBody
    public JsonData getBanner(Integer carouselId) {
        JsCarousel banner = jsCarouselService.getBanner(carouselId);
        return banner != null ? JsonData.buildSuccess(banner) : JsonData.buildError("数据格式异常");
    }

    /**
     * @author WYH
     * @date 2021/11/15 上午 9:28
     * @content : 编辑轮播图
     */
    @RequestMapping("/updateBanner")
    @ResponseBody
    public JsonData updateBanner(JsCarousel jsCarousel) {
        Boolean aBoolean = jsCarouselService.updateBanner(jsCarousel);
        return aBoolean != false ? JsonData.buildSuccess(aBoolean) : JsonData.buildError("数据格式异常");
    }
    /**
     * @author WYH
     * @date 2021/11/15 上午 9:28
     * @content : 添加轮播图
     */
    @RequestMapping("/addBanner")
    @ResponseBody
    public JsonData addBanner(JsCarousel jsCarousel) {
        Boolean aBoolean = jsCarouselService.addBanner(jsCarousel);
        return aBoolean != false ? JsonData.buildSuccess(aBoolean) : JsonData.buildError("数据格式异常");
    }

    /**
     * @author WYH
     * @date 2021/11/15 下午 8:27
     * @content : 删除选中轮播图
     */
    @RequestMapping("/delBanner")
    @ResponseBody
    public JsonData delBanner(Integer carouselId){
        Boolean aBoolean = jsCarouselService.delBanner(carouselId);
        return aBoolean != false ? JsonData.buildSuccess(aBoolean) : JsonData.buildError("数据格式异常");
    }
    /**
     *
     * @author ZPT
     * @date 2021/12/7 20:04
     * @content :到期量
     */
    @RequestMapping("/expireCount")
    @ResponseBody
    public JsonData expireCount(){
        int expireCount = jsCarouselService.expireCount();
        return expireCount>=0?JsonData.buildSuccess(expireCount):JsonData.buildError("服务端错误");
    }
}
